import java.util.Comparator;
import java.util.HashMap;
import java.util.Map;
import java.util.PriorityQueue;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: AliceMana
 * Date: 2023-01-07
 * Time: 21:30
 */
// https://www.nowcoder.com/practice/fc533c45b73a41b0b44ccba763f866ef?
public class Solution2 {
    public static ListNode deleteDuplication(ListNode pHead) {
        Map<Integer, Integer> map = new HashMap<>();
        ListNode cur = pHead;
        while (cur != null) {
            if (!map.containsKey(cur.val)) {
                map.put(cur.val, 1);
            } else {
                map.put(cur.val, map.get(cur.val)+1);
            }
            cur = cur.next;
        }

        cur = pHead;
        ListNode node = new ListNode();
        ListNode nodeCur = node;
        while (cur != null) {
            if (map.get(cur.val) == 1) {
                nodeCur.next = cur;
                nodeCur = nodeCur.next;
            }
            cur = cur.next;
        }
        nodeCur.next = null;
        return node.next;
    }

    public static void main(String[] args) {
        MySingleList list = new MySingleList();

        list.addLast(1);
        list.addLast(1);
        list.addLast(2);
        list.addLast(3);
        list.addLast(3);
        list.addLast(4);
        list.addLast(5);
        list.addLast(5);

        ListNode node = deleteDuplication(list.head);
        System.out.println();
    }
}
